package com.example.neteasemusic.welcome

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Color
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.example.neteasemusic.R
import com.example.neteasemusic.databinding.FragmentWelcomeBinding
import java.util.Timer
import java.util.TimerTask


class WelcomeFragment : Fragment() {
    private lateinit var binding:FragmentWelcomeBinding

    override fun onAttach(context: Context) {
        super.onAttach(context)
        //TODO 测试
        //UserMangaer.getInstance().logOut()

    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        requireActivity().window.statusBarColor = Color.parseColor("#F12A26")
        binding = FragmentWelcomeBinding.inflate(inflater,container,false)
        return binding.root
    }

    @SuppressLint("CheckResult")
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)




        //开启定时器，进入下一个fragment

        Timer().schedule(object : TimerTask(){
            override fun run() {
                requireActivity().runOnUiThread {

                    requireActivity().supportFragmentManager.beginTransaction().apply {
                        replace(R.id.fragmentContainerView,GuideFragment())
                        commit()
                    }
                }
            }
        },2500)

    }

}